package com.zengdw.cli;

import com.zengdw.easytext.api.Analyzer;
import com.zengdw.easytext.api.Fast;
import com.zengdw.easytext.flesch.FleschKincaid;

import java.util.ServiceLoader;

/**
 * @Author: zengd
 * @Date: 2020/7/13 9:49
 * @Version: 1.0
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("cli main");
        //为服务类型 Analyzer 初始化 ServiceLoader
        ServiceLoader<Analyzer> analyzers = ServiceLoader.load(Analyzer.class);
        analyzers.stream()
                //.filter(provider -> isFast(provider.type()))
                .map(ServiceLoader.Provider::get)
//                .filter(analyzer -> {
//                    //System.out.println(analyzer.getName());
//                    return analyzer.getName().equals(args[0]);
//                })
                .forEach(analyzer -> System.out.println(analyzer.getName() + ": " + analyzer.analyze()));
        //Iterable<Analyzer> analyzers = Analyzer.getAnalyzers();
        /*for (Analyzer analyzer : analyzers) {
            System.out.println(analyzer.getName() + ": " + analyzer.analyze());
        }*/

        System.out.println(new FleschKincaid().analyze());

        Thread.sleep(10*1000);
    }

    private static boolean isFast(Class<?> clazz) {
        return clazz.isAnnotationPresent(Fast.class)
                && clazz.getAnnotation(Fast.class).value();
    }
}
